package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.service.ReportService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author zhangyu
 * @data 2023/4/27 10:12
 */
@RestController
@RequestMapping("/admin/report")
@Slf4j
@Api(tags = "统计店铺数据接口")
public class ReportController {
    @Autowired
    private ReportService reportService;

    @GetMapping("/turnoverStatistics")
    @ApiOperation("商家根据不同时间段统计营业额")
    public Result<TurnoverReportVO> getShopMoney(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                                 @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        TurnoverReportVO shopMoney = reportService.getShopMoney(begin, end);
        log.info("shopMoney: {}", shopMoney);
        return Result.success(shopMoney);


    }

    @GetMapping("/userStatistics")
    @ApiOperation("商家查看总用户数和指定时间段新增的用户接口")
    public Result<UserReportVO> getUserCount(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        UserReportVO userCount = reportService.getUserCount(begin, end);
        log.info("userCount: {}", userCount);
        return Result.success(userCount);
    }

    @GetMapping("/ordersStatistics")
    @ApiOperation("商家根据时间段查看订单相关数据")
    public Result<OrderReportVO> getOrderData(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                              @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return Result.success(reportService.getOrderData(begin, end));
    }

    @GetMapping("/top10")
    @ApiOperation("商家查看销量Top10排行")
    public Result<SalesTop10ReportVO> getTop10(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                               @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        SalesTop10ReportVO top10 = reportService.getTop10(begin, end);
        log.info("resss: {}",top10);
        return Result.success(top10);
    }


}
